package com.lyx.dao;

import com.lyx.domain.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IPermissionDao {
    //查询与role关联的所有权限
    @Select("select * from permission where id in (select permissionId from role_permission where roleId=#{roleId})")
    public List<Permission> findPermissionByRoleId(String roleId) throws Exception;

    //查询所有权限
    @Select("select * from permission")
    public List<Permission> findAll() throws Exception;

    //保存权限
    @Insert("insert into permission(permissionName,url) values(#{permissionName},#{url})")
    public void save(Permission permission) throws Exception;

    //根据id查询
    @Select("select * from permission where id=#{permissionId}")
    public Permission findPermissionById(String permissionId);


    //根据权限id删除权限-角色关联表中的数据
    @Delete("delete from role_permission where permissionId=#{permissionId}")
    public void deleteFromRole_PermissionByPermissionId(String permissionId);

    //根据角色id删除角色表中的数据
    @Delete("delete from permission where id=#{permissionId}")
    public void deletePermissionById(String permissionId);

}
